import Vue from 'vue'
import VueRouter from 'vue-router'

// 1.导入路由
import login from '../views/user/login.vue'
import home from '../views/home/home.vue'
import movie from '../views/movie/movie.vue'
import QA from '../views/QA/QA.vue'
import user from '../views/user/user.vue'
import layout from '../views/layout.vue'
import notfound from '../views/notfound/ontfound.vue'
import editor from '../views/user/editor.vue'

Vue.use(VueRouter)
// 2.配置路由规则
const routes = [
  {
    name: 'login',
    path: '/login',
    component: login
  },
  {
    name: 'editor',
    path: '/editor',
    component: editor
  },

  {
    name: 'layout',
    path: '/',
    component: layout,
    children: [

      {
        name: 'home',
        path: '/home',
        component: home
      },
      {
        name: 'movie',
        path: '/movie',
        component: movie
      },
      {
        name: 'QA',
        path: '/QA',
        component: QA
      },
      {
        name: 'user',
        path: '/user',
        component: user
      },
      // 当你进入二级路由，路径为/的时候，重定各到/home(默认加载首页)
      {
        path: '/',
        redirect: '/home'
      }
    ]
  },
  {
    name: 'notfound',
    path: '/notfound',
    component: notfound // 注册404页面，任何页面都要注册才可以使用
  },

  // 如果输入网址所有的路由无法匹配默认重写向到404
  {
    // （1）  *： 任意路径重定向到notfound
    // （2）路由默认从上往下匹配的，如果 可以匹配到则跳转页面，无法匹配继续往下匹配直到所有路由匹配结束
    path: '*',
    redirect: 'notfound'
  }
]

const router = new VueRouter({
  routes
})

export default router
